var app = getApp();
Page({
  data:{
    text:"demo",
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    nav_show:false,
    nav_index : -1,
    is_elite:true,
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    this.get_navs()
    this.get_banner()
    this.get_zhibo()
    this.get_hots()
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  //获取banner数据
  get_banner:function(){
    var that = this
    app.util.footer(that);
    // 初始化导航数据
    app.util.request({
      'url': 'entry/wxapp/wxbanner',
      'cachetime': '30',
      success: function (res) {
        console.log(res)
        if (res.status) {
          console.log(res)
          that.setData({
            banners: res.data
          })
        }
      }
    });
  },
  //分类
  get_navs:function(){
    var that = this
    app.util.footer(that);
    // 初始化导航数据
    app.util.request({
      'url': 'entry/wxapp/goods_type',
      'cachetime': '30',
      success: function (res) {
        console.log(res)
        if (res.status) {
          console.log(res)
          that.setData({
            navs: res.data
          })
        }
      }
    });
  },
  //热点
  get_hots:function(){

  },
  // 显示一级分类图片版
  nav_show:function(){
    this.setData({
      nav_show:true,
      sub_show:false
    })
  },
  // 关闭一级图文栏
  close_category_main:function(){
    this.setData({
      nav_show:false,
      sub_show:false,
    })
  },
  // 显示指定的二级分类导航
  show_category_sub:function(e){
    var that = this;
    var index = e.currentTarget.dataset.id;
    
    console.log(index)
    that.setData({
      sub_navs: that.data.navs[index].types,
      sub_show:true,
      nav_index:index,
      is_elite:false
    })
  },
  // 显示精选栏目
  show_today:function(){
    var that = this
    that.setData({
      nav_index:-1,
      sub_show:false,
      nav_show:false,
      is_elite:true
    })
  },
  // 直播数据
  get_zhibo:function(){
    var that = this
    app.util.request({
      'url': 'entry/wxapp/wxbroadcast',
      data:{
        page:1
      },
      success: function (res) {
        console.log(res)
        if (res.status) {
          console.log(res)
          that.setData({
            zhibo_data: res.data
          })
        }
      }
    });
  },
  // 获取热卖新品数据
  get_hots:function(){
    var that = this
    app.util.request({
      'url': 'entry/wxapp/wxproducts',
      
      success: function (res) {
        console.log(res)
        if (res.status) {
          console.log(res)
          that.setData({
            hot_data: res.data
          })
        }
      }
    });
  }

})